package com.un.ebs.product.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.un.ebs.core.util.StringUtils;
import com.un.ebs.product.domain.ProductClassAttr;
import com.un.ebs.product.domain.ProductClassAttrExt;
import com.un.ebs.product.domain.ProductClassAttrGroup;
import com.un.ebs.product.domain.ProductClassAttrValue;
import com.un.ebs.product.dto.*;
import com.un.ebs.product.mapper.ProductClassAttrExtMapper;
import com.un.ebs.product.mapper.ProductClassAttrGroupMapper;
import com.un.ebs.product.mapper.ProductClassAttrMapper;
import com.un.ebs.product.mapper.ProductClassAttrValueMapper;
import com.un.ebs.product.service.ProductClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.un.ebs.product.service.ProductClassAttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liubo
 * @since 2019-09-16
 */
@RestController
@RequestMapping("/productClassAttr")
@Api(value = "product-class-attr", description = "品类属性")
public class ProductClassAttrController {

    @Autowired
    private ProductClassAttrService service;

    @PostMapping("add")
    @ApiOperation(value = "add", notes = "添加")
    public WebResult save(@RequestBody ProductClassAttrAddDto req) {
        service.add(req);
        return WebUtils.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "update", notes = "修改")
    public WebResult update(@RequestBody ProductClassAttrUpdateDto req) {
        service.update(req);
        return WebUtils.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getById", notes = "根据主键获取单个 ProductClassAttr")
    public WebResult getById(@PathVariable("id") String id) {
        return WebUtils.success(service.queryById(id));
    }

    @GetMapping("list/{classId}")
    @ApiOperation(value = "list", notes = "")
    public WebResult<List<ProductClassAttrVO>> list(@PathVariable("classId") String classId) {
        return WebUtils.success(service.queryViewByClassId(classId));
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "delete", notes = "根据主键删除单个 ProductClassAttr")
    public WebResult delete(@PathVariable("id") String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @PostMapping("changeSort")
    @ApiOperation(value = "changeSort", notes = "修改 ProductClassAttr 的序号")
    public WebResult changeSort(@RequestBody List<SortChangeDto> req) {
        service.changeSort(req);
        return WebUtils.success();
    }

}